﻿Public Class fPeriodos
    Dim daPeriodos As lbGlobalcom.dsGlobalTableAdapters.GLO_PERIODOSTableAdapter
    Dim daEstPer As lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter

    Private Sub fPeriodos_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsGlobal.GLO_PERIODOS.GetChanges() IsNot Nothing Then
                GLO_PERIODOSBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_PERIODOSBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
    'Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    Private Sub fPeriodos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daPeriodos = New lbGlobalcom.dsGlobalTableAdapters.GLO_PERIODOSTableAdapter
            daEstPer = New lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
            'daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
            daEstPer.FillByIdGrupo(DsGlobal.GLO_DATOSTABLAS, "pe")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub btnCargar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargar.Click
        Try
            If Me.DsGlobal.GLO_PERIODOS.GetChanges() IsNot Nothing Then
                GLO_PERIODOSBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_PERIODOSBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daPeriodos.Fill(DsGlobal.GLO_PERIODOS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub GLO_PERIODOSBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GLO_PERIODOSBindingNavigatorSaveItem.Click
        Try
            Validate()
            GLO_PERIODOSBindingSource.EndEdit()
            daPeriodos.Update(DsGlobal.GLO_PERIODOS)
            MessageBox.Show("Se salvarón registros con exito", "Salva Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    'Private Sub GLO_PERIODOSDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles GLO_PERIODOSDataGridView.CellBeginEdit
    '    If e.ColumnIndex = 1 AndAlso GLO_PERIODOSDataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
    '        Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
    '        dt = daClave.GetDataByIdClavePrimaria("GLO_SEDES")
    '        If dt.Count Then
    '            Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
    '            dr = dt.Rows(0)
    '            Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
    '            GLO_PERIODOSDataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
    '            Cons = Nothing
    '            GLO_PERIODOSBindingSource.EndEdit()
    '            daPeriodos.Update(DsGlobal.GLO_PERIODOS)
    '        End If

    '    End If
    'End Sub

    Private Sub GLO_PERIODOSDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles GLO_PERIODOSDataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub GLO_PERIODOSDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles GLO_PERIODOSDataGridView.UserDeletedRow
        Try
            daPeriodos.Update(DsGlobal.GLO_PERIODOS)
            MessageBox.Show("Se elimino registro con exito", "Elimina Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub GLO_PERIODOSDataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles GLO_PERIODOSDataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub
End Class